//package com.bluefuture.modules.app.controller;
//
//import com.bamboo.water_chivalry.common.constant.RedisConstant;
//import com.bamboo.water_chivalry.common.enums.ResultEnum;
//import com.bamboo.water_chivalry.common.exception.GlobalException;
//import com.bamboo.water_chivalry.common.form.UserInfoForm;
//import com.bamboo.water_chivalry.common.form.UserRegisterForm;
//import com.bamboo.water_chivalry.common.sms.SmsService;
//import com.bamboo.water_chivalry.common.utils.ResultVoUtil;
//import com.bamboo.water_chivalry.common.vo.ResultVo;
//import com.bamboo.water_chivalry.common.vo.UserVo;
//import com.bamboo.water_chivalry.service.IUserService;
//import com.bamboo.water_chivalry.shiro.utils.JWTUtil;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.shiro.SecurityUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.validation.BindingResult;
//import org.springframework.web.bind.annotation.*;
//
//import javax.validation.Valid;
//
///**
// * @Author: leo
// * @date: 2019/9/9
// */
//@RestController
//@RequestMapping("user")
//@Slf4j
//@Api(tags = "用户接口")
//public class UserController {
//
//    @Autowired
//    private IUserService userService;
//    @Autowired
//    private SmsService smsService;
//    @Autowired
//    private RedisTemplate<String,Object> redisTemplate;
//    @Value("${spring.profiles.active}")
//    private String profile;
//
//    @PostMapping("register")
//    @ApiOperation(value = "用户注册接口，成功返回0，参数有误返回1020,手机号已注册1026,身份证号已注册1027")
//    public ResultVo<UserVo> register(@Valid @RequestBody UserRegisterForm userRegisterForm, BindingResult bindingResult) {
//        if (bindingResult.hasErrors()) {
//            log.error(bindingResult.getFieldError().getDefaultMessage());
//            throw new GlobalException(ResultEnum.PARAM_ERROR.getCode(), bindingResult.getFieldError().getDefaultMessage());
//        }
//        if (!"dev".equals(profile)) {
//            smsService.checkVerifyCode(userRegisterForm.getMobile(), userRegisterForm.getVerifyCode());
//        }
//        UserVo userVo = userService.register(userRegisterForm);
//        return ResultVoUtil.success(userVo);
//    }
//
//    @GetMapping("verifyCode")
//    @ApiOperation(value = "获取手机验证码，成功返回0，失败返回1000")
//    public ResultVo verifyCode(@RequestParam("mobile") String mobile) {
//        smsService.sendVerifyCode(mobile);
//        return ResultVoUtil.success();
//    }
//
//    @PostMapping("code/verify")
//    @ApiOperation(value = "手机验证码校验，成功返回0，失败返回1001")
//    public ResultVo checkVerifyCode(@RequestParam("mobile") String mobile, @RequestParam("code") String code) {
//        smsService.checkVerifyCode(mobile, code);
//        return ResultVoUtil.success();
//    }
//
//    @PostMapping("forgotPassword")
//    @ApiOperation(value = "忘记密码接口")
//    public ResultVo forgotPasswd(@RequestParam("mobile") String mobile, @RequestParam("code") String code, @RequestParam("newPassword") String newPassword) {
//        smsService.checkVerifyCode(mobile, code);
//        userService.forgotPassword(mobile, newPassword);
//        return ResultVoUtil.success();
//    }
//
//    @PostMapping("login")
//    @ApiOperation(value = "用户登录接口，成功返回0，账号或密码出错返回1021")
//    public ResultVo<UserVo> login(@RequestParam("mobile") String mobile, @RequestParam("password") String password) {
//        UserVo userVo = userService.login(mobile, password);
//        return ResultVoUtil.success(userVo);
//    }
//
//    @PatchMapping("password")
//    @ApiOperation(value = "修改密码接口(需要传递token），成功返回0，原密码输入有错返回1025")
//    public ResultVo updatePassword(@RequestParam("password")String password, @RequestParam("newPassword")String newPassword){
//        String mobile = JWTUtil.getMobile((String) SecurityUtils.getSubject().getPrincipal());
//        userService.resetPassword(mobile,password,newPassword);
//        return ResultVoUtil.success();
//    }
//
//    @PostMapping("logout")
//    @ApiOperation(value = "退出登录，需要在请求头传递token")
//    public ResultVo logout(){
//        String mobile = JWTUtil.getMobile((String) SecurityUtils.getSubject().getPrincipal());
//        redisTemplate.delete(RedisConstant.USER_INFO_PREFIX+mobile);
//        return ResultVoUtil.success();
//    }
//
//    @PutMapping("info")
//    @ApiOperation(value = "【V2.0】修改用户资料")
//    public ResultVo<UserVo> editUserInfo(@Valid @RequestBody UserInfoForm userInfoForm, BindingResult bindingResult){
//        if (bindingResult.hasErrors()) {
//            log.error(bindingResult.getFieldError().getDefaultMessage());
//            throw new GlobalException(ResultEnum.PARAM_ERROR.getCode(), bindingResult.getFieldError().getDefaultMessage());
//        }
//        UserVo userVo = userService.edit(userInfoForm);
//        return ResultVoUtil.success(userVo);
//    }
//
//    @GetMapping("isAuthorized")
//    @ApiOperation(value = "判断用户是否有对应权限,需要传递token")
//    public ResultVo<Boolean> isAuthorized(){
//        return ResultVoUtil.success(userService.isAuthorized());
//    }
//
//}
